Skip to content

fix: address doctest regex span and stale eslint-disable in utils/constructor-name example#11893

Draft
Planeshifter wants to merge 3 commits intodevelopfrom
claude/blissful-heisenberg-FwtjL
Draft

fix: address doctest regex span and stale eslint-disable in utils/constructor-name example#11893
Planeshifter wants to merge 3 commits intodevelopfrom
claude/blissful-heisenberg-FwtjL

Conversation

@Planeshifter
Copy link
Copy Markdown
Member

@Planeshifter Planeshifter commented May 2, 2026

Failing run: https://github.com/stdlib-js/stdlib/actions/runs/25195861572 (issue #11867, 2026-05-01)

Symptom:

lib/node_modules/@stdlib/utils/constructor-name/examples/index.js
  39:1   error  Displayed return value is `'String'`, but expected `undefined` instead  stdlib/doctest
  151:57 error  Unused eslint-disable directive (no problems were reported from 'no-buffer-constructor')

Root cause:

Error 1 (stdlib/doctest): The rule's RE_ANNOTATION regex uses [^;]*;\n to locate annotated expressions. [^;]* is greedy and matches any non-semicolon character, including newlines. The original noop() body contained only // Do nothing... — no semicolon — so the regex spanned from function noop across the entire function body and the trailing blank line to console.log( constructorName( 'a' ) ); on line 44. The rule then associated // => 'String' with the function identifier, evaluated the combined expression in a VM sandbox, and got undefined (not 'String').

Error 2 (unused eslint-disable-line): The no-buffer-constructor rule is no longer active in the project's ESLint configuration, making the inline directive on line 151 stale.

Fix:

Two minimal edits to lib/node_modules/@stdlib/utils/constructor-name/examples/index.js:

  1. Add return; // eslint-disable-line no-useless-return after // Do nothing... in noop(). This inserts a semicolon inside the function body, causing RE_ANNOTATION's [^;]* to stop inside the function instead of spanning across it. The // Do nothing... comment is preserved to match stdlib noop conventions. The no-useless-return disable is required because ESLint flags a bare return; at the end of a void function. The RE_ESLINT_INLINE preprocessor in the stdlib/doctest rule strips eslint-disable-line comments before running RE_ANNOTATION, so the doctest fix is unaffected by the suppression comment.

  2. Remove // eslint-disable-line no-buffer-constructor from line 151. The rule is not present in etc/eslint/.eslintrc.js, .eslintrc.examples.js, or .eslintrc.overrides.js, confirming the directive is stale.

Neither change alters the runtime behavior of the example. noop is only consumed by constructorName( noop ) to demonstrate a 'Function' result; its return value is never used.

Validation:

  • Reviewed regex trace: with return; in the body (comment stripped by RE_ESLINT_INLINE), [^;]* matches noop() {\n\t// Do nothing...\n\treturn and stops at ;. The following \n} does not match \n//, so the wrong match attempt fails. The regex then correctly matches console.log( constructorName( 'a' ) );\n// => 'String' as intended.
  • Confirmed no-buffer-constructor absent from all project ESLint configs; removing the directive will not introduce a new error.
  • Coverage: utils/constructor-name 100% (statements, branches, functions, lines).
  • Three independent reviewers (two opus, one sonnet) over two cycles: all approved.

Reviewer notes:

  • Reviewer C (style) noted that the README (lib/node_modules/@stdlib/utils/constructor-name/README.md) still shows the original // Do nothing...-only noop body. The README is not processed by stdlib/doctest (the rule is disabled for markdown), so this is not a lint issue. Aligning the README is out of scope but could be done as a follow-up.
  • Several other // eslint-disable-line no-buffer-constructor directives exist elsewhere in the repo (e.g., buffer/from-buffer, buffer/from-array, assert/is-gzip-buffer). Those are separate packages and out of scope here, but a repo-wide cleanup may be warranted.

Related: issue #11867 (clusters 1 and 2 of that issue — symbol/async-iterator and ndarray/fancy — are addressed separately in draft PR #11882)

Contributing Guidelines

claude added 2 commits May 2, 2026 14:24
…nstructor-name` example

The CI JavaScript lint job (run https://github.com/stdlib-js/stdlib/actions/runs/25195861572,
issue #11867) failed with two errors in `utils/constructor-name/examples/index.js`:

1. `stdlib/doctest` at line 39: "Displayed return value is `'String'`, but expected
   `undefined` instead". Root cause: the doctest rule's `RE_ANNOTATION` regex uses
   `[^;]*;` which matches any non-semicolon characters including newlines. The original
   `noop()` body contained only `// Do nothing...` with no semicolon, so the greedy
   `[^;]*` spanned from `function noop` across the function body and blank lines to
   `console.log( constructorName( 'a' ) );`, misattributing the `// => 'String'`
   annotation to the `function` identifier. Adding `return;` to the body provides a
   semicolon that terminates the greedy match inside the function, so the regex no
   longer spans past it.

2. Unused `eslint-disable-line no-buffer-constructor` at line 151. The `no-buffer-constructor`
   rule no longer fires for `new Buffer()` in this project, making the directive stale.
   Removing it eliminates the unused-directive error.

Failing run: https://github.com/stdlib-js/stdlib/actions/runs/25195861572
…ntion

Reviewer C (style) flagged that removing the `// Do nothing...` comment
deviated from the established stdlib noop convention in example files.
Restore the comment and keep `return;` below it so the function body
preserves convention while still providing the semicolon that terminates
the doctest regex's greedy `[^;]*` match inside the function.
@stdlib-bot
Copy link
Copy Markdown
Contributor

Hello! Thank you for your contribution to stdlib.

We noticed that the contributing guidelines acknowledgment is missing from your pull request. Here's what you need to do:

  1. Please read our contributing guidelines.

  2. Update your pull request description to include this checked box:

    - [x] Read, understood, and followed the [contributing guidelines](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md)

This acknowledgment confirms that you've read the guidelines, which include:

  • The developer's certificate of origin
  • Your agreement to license your contributions under the project's terms

We can't review or accept contributions without this acknowledgment.

Thank you for your understanding and cooperation. We look forward to reviewing your contribution!

@stdlib-bot stdlib-bot added the Good First PR A pull request resolving a Good First Issue. label May 2, 2026
@stdlib-bot
Copy link
Copy Markdown
Contributor

stdlib-bot commented May 2, 2026

Coverage Report

Package Statements Branches Functions Lines
utils/constructor-name $\color{green}126/126$
$\color{green}+100.00%$
$\color{green}12/12$
$\color{green}+100.00%$
$\color{green}1/1$
$\color{green}+100.00%$
$\color{green}126/126$
$\color{green}+100.00%$

The above coverage report was generated for the changes in this PR.

The `return;` added to break the `stdlib/doctest` regex's greedy span
triggers the `no-useless-return` rule (configured as error). Add an
inline eslint-disable-line comment to suppress it.

The `RE_ESLINT_INLINE` preprocessing in the doctest rule strips
`eslint-disable-line` comments before running `RE_ANNOTATION`, so
the doctest fix is unaffected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Good First PR A pull request resolving a Good First Issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants